/**
 * Copyright [2016-2017] [yadong.zhang]
 * <p/>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package me.zhyd.music.controller;

import me.zhyd.music.business.api.WangyiApi;
import me.zhyd.music.business.model.WangyiPlay;
import me.zhyd.music.business.vo.ResponseVO;
import me.zhyd.music.business.service.WangyiPlayService;
import me.zhyd.music.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author yadong.zhang email:yadong.zhang0415(a)gmail.com
 * @version 1.0
 * @date 2018/3/5 19:05
 * @since 1.0
 */
@Controller
public class MusicWebController {

    @Autowired
    private WangyiPlayService wangyiPlayService;
    @Autowired
    private WangyiApi wangyiApi;

    @RequestMapping("/")
    public ModelAndView player() {
        return ResultUtil.view("music");
    }

    @RequestMapping("/index.html")
    public ModelAndView index() {
        return ResultUtil.view("music");
    }

    @RequestMapping("/music.html")
    public ModelAndView music() {
        return ResultUtil.view("music");
    }

    @RequestMapping("/playList")
    @ResponseBody
    public Object list() {
        WangyiPlay wangyiPlay = wangyiPlayService.getDefault();
        return wangyiApi.getPlaylist(wangyiPlay.getPlayId());
    }

    @RequestMapping("/lrc/{musicId}")
    @ResponseBody
    public ResponseVO getLrc(@PathVariable("musicId") String musicId) {
        return wangyiApi.getLyric(musicId);
    }

}